package com.shensi.appCollect.controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.shensi.appCollect.service.FleetCardService;
import com.shensi.appCollect.utils.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Api(tags = "车队卡信息管理")
@RequestMapping("/fleetCard")
public class FleetCardController {

    @Autowired
    private FleetCardService fleetCardService;

    @GetMapping(value = "/enterpriseId/{enterpriseId}/keyword/{keyword}")
    @ApiOperation(value = "根据关键词获取车队卡信息列表", httpMethod = "GET", notes = "根据关键词获取车队卡信息列表")
    public String getFleetCardList(@PathVariable Long enterpriseId, @PathVariable String keyword) {
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        return gson.toJson(ResultData.success(fleetCardService.selectFleetCardByKeyword(enterpriseId, keyword)));
    }

    @GetMapping(value = "/{cardNumber}")
    @ApiOperation(value = "根据主卡号获取车队卡信息", httpMethod = "GET", notes = "根据主卡号获取车队卡信息")
    public String getFleetCard(@PathVariable String cardNumber) {
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        return gson.toJson(ResultData.success(fleetCardService.selectFleetCardByCardNumber(cardNumber)));
    }
}
